using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DgvFilterPopup;
using <Application>.<Business>;
using <Application>.<Data>;

namespace <Application>.<Presentation>
{
    public partial class frm<OwnerU>_<TableU> : System.Windows.Forms.UserControl
    {
        public frm<OwnerU>_<TableU>()
        {
            InitializeComponent();
        }

        private bool bAddMode = false;
        private bool bEditMode = false;
        private bool bDeleteMode = false;
        private int iRow = 0;

        public <DRType> <DRField>;
        
        public bool AddMode {
            get { return bAddMode; }
            set { bAddMode = value; }
        }

        public bool EditMode {
            get { return bEditMode; }
            set { bEditMode = value; }
        }

        public bool DeleteMode {
            get { return bDeleteMode; }
            set { bDeleteMode = value; }
        }

        public int Row {
            get { return iRow; }
            set { iRow = value; }
        }

        private void frm<OwnerU>_<TableU>_Load(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            <If Loop>
            <IsFKey>
            <And>
            <IsComboBox (Db)>
            Load<OwnerU>_<TableU>_<ROwnerU>_<RTableU>ComboBox<MiscTag>();
            </If Loop>
            LoadGridCode(true);
            ShowToolStripItems("Cancel");
	        DgvFilterManager filterManager = new DgvFilterManager(gridCode);
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        <If Loop>
        <IsFKey>
        <And>
        <IsComboBox (Db)>
        private void Load<OwnerU>_<TableU>_<ROwnerU>_<RTableU>ComboBox<MiscTag>()
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            cb<FieldU>.DataSource = <OwnerU>_<TableU>_<ROwnerU>_<RTableU>DataClass<MiscTag>.Select<ROwnerU>_<RTableU>();
            cb<FieldU>.DisplayMember = "<RDisplayFieldU>";
            cb<FieldU>.ValueMember = "<RFieldU>";
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        </If Loop>
        public void LoadGridCode(bool load)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            try
            {
                gridCode.RowHeadersVisible = false;
                gridCode.DataSource = null;
                if (load == true) { 
                    gridCode.DataSource = <OwnerU>_<TableU>DataClass.Select_Records(<DRField>);
                    if (gridCode.Rows.Count == 0) {
                        ShowToolStripItems("No Record");
                    }
                    else
                    {
        	<If Loop>
	          <IsMoney>
                        gridCode.Columns[<ColNo>].DefaultCellStyle.Format = "c";
		  <IsSmallMoney>
                        gridCode.Columns[<ColNo>].DefaultCellStyle.Format = "c";
                  <IsNumber>
                  <And>
                  <IsNotFKey>
                        gridCode.Columns[<ColNo>].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
        	</If Loop>
                    }
                }
            }
            catch { }
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void gridCode_Click(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            try
            {
                Row = gridCode.CurrentRow.Index;
            }
            catch { }
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void gridCode_DoubleClick(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            try
            {
                if (gridCode.Rows.Count > 0)
                {
                    ShowHideTabPages(TPForm, TPGrid);
                    Row = gridCode.CurrentRow.Index;
                    Edit();
                }
            }
            catch { }
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void Add()
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            this.AddMode = true;
            this.EditMode = false;
            this.DeleteMode = false;

            ClearRecord();
            EnableRecord(true);
 -----------------------------------------------------<Comment>
            <If Loop>
            <IsUniqueIdentifier>
            <And>
            <IsTextBox>
            this.tb<FieldU>.Text = Guid.NewGuid().ToString();
            <IsUniqueIdentifier>
            <And>
            <IsMaskedTextBox>
            this.tb<FieldU>.Text = Guid.NewGuid().ToString();
            </If Loop>
 -----------------------------------------------------<Comment>
            <If Loop>
           <IsNotIdentity>
            <And>
            <IsCheckBox>
            cb<FieldU>.Select();
            <ExitLoop>
           <IsNotIdentity>
            <And>
            <IsNumericUpDown>
            nud<FieldU>.Select();
            <ExitLoop>
           <IsNotIdentity>
            <And>
            <IsDateTimePicker>
            dtp<FieldU>.Select();
            <ExitLoop>
           <IsNotIdentity>
            <And>
            <IsTextBox>
            tb<FieldU>.Select();
            <ExitLoop>
           <IsNotIdentity>
            <And>
            <IsMaskedTextBox>
            mtb<FieldU>.Select();
            <ExitLoop>
           <IsNotIdentity>
            <And>
            <IsMultilineTextBox>
            mtb<FieldU>.Select();
            <ExitLoop>
           <IsNotIdentity>
            <And>
            <IsRichTextBox>
            rtb<FieldU>.Select();
            <ExitLoop>
           <IsNotIdentity>
            <And>
            <IsPictureBox>
            pb<FieldU>.Select();
            <ExitLoop>
           <IsNotIdentity>
            <And>
            <IsComboBox>
            cb<FieldU>.Select();
            <ExitLoop>
           <IsNotIdentity>
            <And>
            <IsComboBox (Db)>
            cb<FieldU>.Select();
            <ExitLoop>
            </If Loop>
-----------------------------------------------------<Comment>
        <If Loop>
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsCheckBox>
            cb<FieldU>.Checked = <DRField>;
              <ExitLoop>
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsNumericUpDown> 
            nud<FieldU>.Value = <DRField>;
              <ExitLoop>
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsDateTimePicker>
            dtp<FieldU>.Value = <DRField>;
              <ExitLoop>
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsTextBox>
            tb<FieldU>.Text = <DRField>;
              <ExitLoop>
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsMaskedTextBox>
            mtb<FieldU>.Text = <DRField>;
              <ExitLoop>
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsMultilineTextBox>
            mtb<FieldU>.Text = <DRField>;
              <ExitLoop>
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsRichTextBox>
            rtb<FieldU>.Text = <DRField>;
              <ExitLoop>
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsPictureBox>
            pb<FieldU>.Value = <DRField>;
              <ExitLoop>
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsComboBox>
            cb<FieldU>.Text = <DRField>;
              <ExitLoop>
        </If Loop>
-----------------------------------------------------<Comment>
            ShowHideTabPages(TPForm, TPGrid);
            ShowToolStripItems("Add");
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void GetData()
        {
            ClearRecord();

            <OwnerU>_<TableU> cls<OwnerU>_<TableU> = new <OwnerU>_<TableU>();
            <If Loop>
            <IsPKey>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(gridCode[<ColNo>, Row].Value);
            </If Loop>
            <If Loop>
            <IsNotPKey>
            <And>
            <IsIdentity>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(gridCode[<ColNo>, Row].Value);
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(gridCode[<ColNo>, Row].Value);
            <ExitLoop>
            </If Loop>
            cls<OwnerU>_<TableU> = <OwnerU>_<TableU>DataClass.Select_Record(cls<OwnerU>_<TableU>);

            if (cls<OwnerU>_<TableU> != null){
                try
                { 
                    <If Loop>
                    <IsCheckBox>
                    <And>
                    <IsNull>
                    if (cls<OwnerU>_<TableU>.<Field> is null) { cb<FieldU>.Checked = default(<CSType>); } else { cb<FieldU>.Checked = <Convert>(cls<OwnerU>_<TableU>.<Field>); }
                    <IsNumericUpDown>
                    <And>
                    <IsNull>
                    if (cls<OwnerU>_<TableU>.<Field> is null) { nud<FieldU>.Value = default(<CSType>); } else { nud<FieldU>.Value = <Convert>(cls<OwnerU>_<TableU>.<Field>); }
                    <IsDateTimePicker>
                    <And>
                    <IsNull>
                    if (cls<OwnerU>_<TableU>.<Field> is null) { dtp<FieldU>.Value = DateTime.Now; } else { dtp<FieldU>.Value = <Convert>(cls<OwnerU>_<TableU>.<Field>); }
                    <IsTextBox>
                    <And>
                    <IsNull>
                    if (cls<OwnerU>_<TableU>.<Field> is null) { tb<FieldU>.Text = default(<CSType>); } else { tb<FieldU>.Text =  System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>); }
                    <IsMaskedTextBox>
                    <And>
                    <IsNull>
                    if (cls<OwnerU>_<TableU>.<Field> is null) { mtb<FieldU>.Text = default(<CSType>); } else { mtb<FieldU>.Text =  System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>); }
                    <IsMultilineTextBox>
                    <And>
                    <IsNull>
                    if (cls<OwnerU>_<TableU>.<Field> is null) { mtb<FieldU>.Text = default(<CSType>); } else { mtb<FieldU>.Text =  System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>); }
                    <IsRichTextBox>
                    <And>
                    <IsNull>
                    if (cls<OwnerU>_<TableU>.<Field> is null) { rtb<FieldU>.Text = default(<CSType>); } else { rtb<FieldU>.Text =  System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>); }
                    <IsPictureBox>
                    <And>
                    <IsNull>
                    if (cls<OwnerU>_<TableU>.<Field> is null) { pb<FieldU>.Value = default(<CSType>); } else { pb<FieldU>.Value = <Convert>(cls<OwnerU>_<TableU>.<Field>); }
                    <IsComboBox>
                    <And>
                    <IsNull>
                    if (cls<OwnerU>_<TableU>.<Field> is null) { cb<FieldU>.Text = default(<CSType>); } else { cb<FieldU>.Text =  System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>); }
                    <IsComboBox (Db)>
                    <And>
                    <IsNull>
                    if (cls<OwnerU>_<TableU>.<Field> is null) { cb<FieldU>.SelectedValue = default(<CSType>); } else { cb<FieldU>.SelectedValue = <Convert>(cls<OwnerU>_<TableU>.<Field>); }
--------------------------------------------------------------------------------------------------------<Comment>
                    <IsCheckBox>
                    <And>
                    <IsNotNull>
                    cb<FieldU>.Checked = <Convert>(cls<OwnerU>_<TableU>.<Field>);
                    <IsNumericUpDown>
                    <And>
                    <IsNotNull>
                    nud<FieldU>.Value = <Convert>(cls<OwnerU>_<TableU>.<Field>);
                    <IsDateTimePicker>
                    <And>
                    <IsNotNull>
                    dtp<FieldU>.Value = <Convert>(cls<OwnerU>_<TableU>.<Field>);
                    <IsTextBox>
                    <And>
                    <IsNotNull>
                    tb<FieldU>.Text =  System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>);
                    <IsMaskedTextBox>
                    <And>
                    <IsNotNull>
                    mtb<FieldU>.Text =  System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>);
                    <IsMultilineTextBox>
                    <And>
                    <IsNotNull>
                    mtb<FieldU>.Text =  System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>);
                    <IsRichTextBox>
                    <And>
                    <IsNotNull>
                    rtb<FieldU>.Text =  System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>);
                    <IsPictureBox>
                    <And>
                    <IsNotNull>
                    pb<FieldU>.Value = <Convert>(cls<OwnerU>_<TableU>.<Field>);
                    <IsComboBox>
                    <And>
                    <IsNotNull>
                    cb<FieldU>.Text =  System.Convert.ToString(cls<OwnerU>_<TableU>.<Field>);
                    <IsComboBox (Db)>
                    <And>
                    <IsNotNull>
                    cb<FieldU>.SelectedValue = <Convert>(cls<OwnerU>_<TableU>.<Field>);
                    </If Loop>
                }
                catch{}
            }
        }

        private void Edit()
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            AddMode = false;
            EditMode = true;
            DeleteMode = false;

            GetData();

            EnableRecord(true);
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsNumericUpDown>
            nud<FieldU>.Enabled = false;
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsTextBox>
            tb<FieldU>.Enabled = false;
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMaskedTextBox>
            mtb<FieldU>.Enabled = false;
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMultilineTextBox>
            mtb<FieldU>.Enabled = false;
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsRichTextBox>
            rtb<FieldU>.Enabled = false;
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsComboBox (Db)>
            cb<FieldU>.Enabled = false;
            <IsNotIdentity>
            <And>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsNumericUpDown>
            nud<FieldU>.Enabled = false;
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsTextBox>
            tb<FieldU>.Enabled = false;
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMaskedTextBox>
            mtb<FieldU>.Enabled = false;
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMultilineTextBox>
            mtb<FieldU>.Enabled = false;
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsRichTextBox>
            rtb<FieldU>.Enabled = false;
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsComboBox (Db)>
            cb<FieldU>.Enabled = false;
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsNotPKey>
            <And>
            <IsCheckBox>
            cb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsNotPKey>
            <And>
            <IsNumericUpDown>
            nud<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsNotPKey>
            <And>
            <IsDateTimePicker>
            dtp<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsNotPKey>
            <And>
            <IsTextBox>
            tb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsNotPKey>
            <And>
            <IsMaskedTextBox>
            mtb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsNotPKey>
            <And>
            <IsMultilineTextBox>
            mtb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsNotPKey>
            <And>
            <IsRichTextBox>
            rtb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsNotPKey>
            <And>
            <IsComboBox>
            cb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsNotPKey>
            <And>
            <IsComboBox (Db)>
            cb<FieldU>.Select();
            <ExitLoop>
            </If Loop>
-----------------------------------------------------<Comment>

            ShowHideTabPages(TPForm, TPGrid);
            ShowToolStripItems("Edit");
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void Delete()
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            AddMode = false;
            EditMode = false;
            DeleteMode = true;

            GetData();

            EnableRecord(false);
            ShowHideTabPages(TPForm, TPGrid);
            ShowToolStripItems("Delete");
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void EnableRecord(bool YesNo)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsCheckBox>
            cb<FieldU>.Enabled = YesNo;
            <IsNotIdentity>
            <And>
            <IsNumericUpDown>
            nud<FieldU>.Enabled = YesNo;
            <IsNotIdentity>
            <And>
            <IsDateTimePicker>
            dtp<FieldU>.Enabled = YesNo;
            <IsNotIdentity>
            <And>
            <IsTextBox>
            tb<FieldU>.Enabled = YesNo;
            <IsNotIdentity>
            <And>
            <IsMaskedTextBox>
            mtb<FieldU>.Enabled = YesNo;
            <IsNotIdentity>
            <And>
            <IsMultilineTextBox>
            mtb<FieldU>.Enabled = YesNo;
            <IsNotIdentity>
            <And>
            <IsRichTextBox>
            rtb<FieldU>.Enabled = YesNo;
            <IsNotIdentity>
            <And>
            <IsPictureBox>
            pb<FieldU>.Enabled = YesNo;
            <IsNotIdentity>
            <And>
            <IsComboBox>
            cb<FieldU>.Enabled = YesNo;
            <IsNotIdentity>
            <And>
            <IsComboBox (Db)>
            cb<FieldU>.Enabled = YesNo;
            </If Loop>
-----------------------------------------------------<Comment>
        <If Loop>
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsCheckBox>
            cb<FieldU>.Enabled = false;
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsNumericUpDown>
            nud<FieldU>.Enabled = false;
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsDateTimePicker>
            dtp<FieldU>.Enabled = false;
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsTextBox>
            tb<FieldU>.Enabled = false;
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsMaskedTextBox>
            mtb<FieldU>.Enabled = false;
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsMultilineTextBox>
            mtb<FieldU>.Enabled = false;
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsRichTextBox>
            rtb<FieldU>.Enabled = false;
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsPictureBox>
            pb<FieldU>.Enabled = false;
	   <IsFKey>
           <And>
           <IsNotComboBox (Db)>
           <And>
           <IsComboBox>
            cb<FieldU>.Enabled = false;
        </If Loop>
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void ClearRecord()
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            <If Loop>
            <IsCheckBox>
            cb<FieldU>.Text = null;
            <IsNumericUpDown>
            nud<FieldU>.Value = 0;
            <IsDateTimePicker>
            dtp<FieldU>.Text = null;
            <IsTextBox>
            tb<FieldU>.Text = null;
            <IsMaskedTextBox>
            mtb<FieldU>.Text = null;
            <IsMultilineTextBox>
            mtb<FieldU>.Text = null;
            <IsRichTextBox>
            rtb<FieldU>.Text = null;
            <IsPictureBox>
            pb<FieldU>.Text = null;
            <IsComboBox>
            cb<FieldU>.SelectedIndex = -1;
            <IsComboBox (Db)>
            cb<FieldU>.SelectedIndex = -1;
            </If Loop>
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void GoBack_To_Grid()
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            bool gridOK = false;
            try
            {
                LoadGridCode(true);
                ShowToolStripItems("Cancel");
                gridCode.Rows[Row].Selected = true;
                gridCode.FirstDisplayedScrollingRowIndex = Row;

                gridOK = true;
            }
            catch
            {
                //Hide error message.
            }
            finally
            {
                if (gridOK == false)
                {
                    ShowToolStripItems("Cancel");
                }
            }
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void butCancel_Click(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            ShowToolStripItems("Cancel");
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void butApply_Click(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            if (this.AddMode == true) {
                this.InsertRecord();
            }
            else if (this.EditMode == true) {
                this.UpdateRecord();
            }
            else if (this.DeleteMode == true) {
                this.DeleteRecord();
            }
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void SetData(<OwnerU>_<TableU> cls<OwnerU>_<TableU>)
        {
                <If Loop>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
            cls<OwnerU>_<TableU>.<FieldU> = cb<FieldU>.Checked ? true : false;                        
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
            if (string.IsNullOrEmpty(nud<FieldU>.Text)) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(nud<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
            if (string.IsNullOrEmpty(dtp<FieldU>.Text)) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(dtp<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
            if (string.IsNullOrEmpty(tb<FieldU>.Text)) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(tb<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
            if (string.IsNullOrEmpty(mtb<FieldU>.Text)) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(mtb<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
            if (string.IsNullOrEmpty(mtb<FieldU>.Text)) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(mtb<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
            if (string.IsNullOrEmpty(rtb<FieldU>.Text)) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(rtb<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
                        
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(cb<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNull>
                    <And>
                    <IsNullable>
            if (string.IsNullOrEmpty(cb<FieldU>.SelectedValue.ToString())) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(cb<FieldU>.SelectedValue); }
--------------------------------------------------------------------------------------------------------<Comment>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
            cls<OwnerU>_<TableU>.<FieldU> = cb<FieldU>.Checked ? true : false;  
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
            if (string.IsNullOrEmpty(nud<FieldU>.Text)) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(nud<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
            if (string.IsNullOrEmpty(dtp<FieldU>.Text)) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(dtp<FieldU>.Text); }
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
            if (string.IsNullOrEmpty(tb<FieldU>.Text)) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = tb<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
            if (string.IsNullOrEmpty(mtb<FieldU>.Text)) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = mtb<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
            if (string.IsNullOrEmpty(mtb<FieldU>.Text)) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = mtb<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
            if (string.IsNullOrEmpty(rtb<FieldU>.Text)) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = rtb<FieldU>.Text; }
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
                        
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(cb<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNull>
                    <And>
                    <IsNotNullable>
            if (string.IsNullOrEmpty(cb<FieldU>.SelectedValue.ToString())) {
                cls<OwnerU>_<TableU>.<FieldU> = null;
            } else {
                cls<OwnerU>_<TableU>.<FieldU> = <Convert>(cb<FieldU>.SelectedValue); }
--------------------------------------------------------------------------------------------------------<Comment>
                    <IsNotIdentity>
                    <And>
                    <IsCheckBox>
                    <And>
                    <IsNotNull>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(cb<FieldU>.Checked ? true : false);
                    <IsNotIdentity>
                    <And>
                    <IsNumericUpDown>
                    <And>
                    <IsNotNull>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(nud<FieldU>.Value);
                    <IsNotIdentity>
                    <And>
                    <IsDateTimePicker>
                    <And>
                    <IsNotNull>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(dtp<FieldU>.Value);
                    <IsNotIdentity>
                    <And>
                    <IsTextBox>
                    <And>
                    <IsNotNull>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(tb<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsMaskedTextBox>
                    <And>
                    <IsNotNull>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(mtb<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsMultilineTextBox>
                    <And>
                    <IsNotNull>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(mtb<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsRichTextBox>
                    <And>
                    <IsNotNull>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(rtb<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsPictureBox>
                    <And>
                    <IsNotNull>
                        
                    <IsNotIdentity>
                    <And>
                    <IsComboBox>
                    <And>
                    <IsNotNull>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(cb<FieldU>.Text);
                    <IsNotIdentity>
                    <And>
                    <IsComboBox (Db)>
                    <And>
                    <IsNotNull>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(cb<FieldU>.SelectedValue);
--------------------------------------------------------------------------------------------------------<Comment>
                </If Loop>
        }

        private void InsertRecord()
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            <OwnerU>_<TableU> cls<OwnerU>_<TableU> = new <OwnerU>_<TableU>();
            if (VerifyData() == true) {
                SetData(cls<OwnerU>_<TableU>);
                Boolean bSucess = new Boolean();
                bSucess = <OwnerU>_<TableU>DataClass.Add(cls<OwnerU>_<TableU>);
                if (bSucess == true) {
                    GoBack_To_Grid(); }
                else {
                    MessageBox.Show("Insert failed.", "Error", MessageBoxButtons.OK); }
            }
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void UpdateRecord()
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            <OwnerU>_<TableU> cls<OwnerU>_<TableU> = new <OwnerU>_<TableU>();
            <If Loop>
            <IsPKey>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(gridCode[<ColNo>, Row].Value);
            </If Loop>
            <If Loop>
            <IsNotPKey>
            <And>
            <IsIdentity>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(gridCode[<ColNo>, Row].Value);
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(gridCode[<ColNo>, Row].Value);
            <ExitLoop>
            </If Loop>
            if (VerifyData() == true) {
                SetData(cls<OwnerU>_<TableU>);
                Boolean bSucess = new Boolean();
                bSucess = <OwnerU>_<TableU>DataClass.Update(cls<OwnerU>_<TableU>);
                if (bSucess == true) {
                    GoBack_To_Grid(); }
                else {
                    MessageBox.Show("Update failed.", "Error", MessageBoxButtons.OK);}
            }
            this.Cursor = System.Windows.Forms.Cursors.Default;
        } 

        private void DeleteRecord()
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            <OwnerU>_<TableU> cls<OwnerU>_<TableU> = new <OwnerU>_<TableU>();
            <If Loop>
            <IsPKey>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(gridCode[<ColNo>, Row].Value);
            </If Loop>
            <If Loop>
            <IsNotPKey>
            <And>
            <IsIdentity>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(gridCode[<ColNo>, Row].Value);
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(gridCode[<ColNo>, Row].Value);
            <ExitLoop>
            </If Loop>
            DialogResult result = MessageBox.Show("Are you sure? Delete this record?", "Delete", MessageBoxButtons.YesNo,  MessageBoxIcon.Question);
            {
            if (result == DialogResult.Yes) {
                SetData(cls<OwnerU>_<TableU>);
                Boolean bSucess = new Boolean();
                bSucess = <OwnerU>_<TableU>DataClass.Delete(cls<OwnerU>_<TableU>);
                if (bSucess == true) {
                    GoBack_To_Grid(); }
                else {
                    MessageBox.Show("Delete failed.", "Error", MessageBoxButtons.OK); }
                }
            }
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }  

        private Boolean VerifyData()
        {
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsCheckBox>
            
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsNumericUpDown>
            if (nud<FieldU>.Text == "") {
                MessageBox.Show("<FieldC> is Required", "Error", MessageBoxButtons.OK);
                nud<FieldU>.Select();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsDateTimePicker>
            
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsTextBox>
            if (tb<FieldU>.Text == "") {
                MessageBox.Show("<FieldC> is Required", "Error", MessageBoxButtons.OK);
                tb<FieldU>.Select();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsMaskedTextBox>
            if (mtb<FieldU>.Text == "") {
                MessageBox.Show("<FieldC> is Required", "Error", MessageBoxButtons.OK);
                mtb<FieldU>.Select();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsMultilineTextBox>
            if (mtb<FieldU>.Text == "") {
                MessageBox.Show("<FieldC> is Required", "Error", MessageBoxButtons.OK);
                mtb<FieldU>.Select();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsRichTextBox>
            if (rtb<FieldU>.Text == "") {
                MessageBox.Show("<FieldC> is Required", "Error", MessageBoxButtons.OK);
                rtb<FieldU>.Select();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsPictureBox>
            
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsComboBox>
            if (cb<FieldU>.SelectedIndex == -1) {
                MessageBox.Show("<FieldC> is Required", "Error", MessageBoxButtons.OK);
                cb<FieldU>.Select();
                return false;}
            <IsNotIdentity>
            <And>
            <IsNotNull>
            <And>
            <IsComboBox (Db)>
            if (cb<FieldU>.SelectedIndex == -1) {
                MessageBox.Show("<FieldC> is Required", "Error", MessageBoxButtons.OK);
                cb<FieldU>.Select();
                return false;}          
            </If Loop>
---------------------------------------<Comment>
            <If Loop>
	            <IsNotIdentityCount>
            if (
	            <ExitLoop>
            </If Loop>
            <If Loop>
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsNumericUpDown>
            nud<FieldU>.Text != "" 
	            <ExitLoop>
             	    <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsTextBox>
            tb<FieldU>.Text != "" 
	            <ExitLoop>
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsMaskedTextBox>
            mtb<FieldU>.Text != "" 
	            <ExitLoop>
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsMultilineTextBox>
            mtb<FieldU>.Text != "" 
	            <ExitLoop>
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsRichTextBox>
            rtb<FieldU>.Text != "" 
	            <ExitLoop>
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsComboBox (Db)>
            cb<FieldU>.SelectedIndex != -1 
	            <ExitLoop>
            </If Loop>
            <If Loop>
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsNumericUpDown>
           	    <And>
           	    <IsCurRow<>[0]>
            && nud<FieldU>.Text != "" 
             	    <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsTextBox>
           	    <And>
           	    <IsCurRow<>[0]>
            && tb<FieldU>.Text != "" 
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsMaskedTextBox>
           	    <And>
           	    <IsCurRow<>[0]>
            && mtb<FieldU>.Text != "" 
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsMultilineTextBox>
           	    <And>
           	    <IsCurRow<>[0]>
            && mtb<FieldU>.Text != "" 
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsRichTextBox>
           	    <And>
           	    <IsCurRow<>[0]>
            && rtb<FieldU>.Text != "" 
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsComboBox (Db)>
           	    <And>
           	    <IsCurRow<>[0]>
            && cb<FieldU>.SelectedIndex != -1 
            </If Loop>
            <If Loop>
	            <IsNotIdentityCount>
	            <And>
	            <IsNotPKeyCount>
	            <And>
	            <IsNumericUpDown>
            nud<FieldU>.Text != "" 
	            <ExitLoop>
	            <IsNotIdentityCount>
	            <And>
	            <IsNotPKeyCount>
	            <And>
	            <IsTextBox>
            tb<FieldU>.Text != "" 
	            <ExitLoop>
	            <IsNotIdentityCount>
	            <And>
	            <IsNotPKeyCount>
	            <And>
	            <IsMaskedTextBox>
            mtb<FieldU>.Text != "" 
	           <ExitLoop>
	            <IsNotIdentityCount>
	            <And>
	            <IsNotPKeyCount>
	            <And>
	            <IsMultilineTextBox>
            mtb<FieldU>.Text != "" 
	           <ExitLoop>
	            <IsNotIdentityCount>
	            <And>
	            <IsNotPKeyCount>
	            <And>
	            <IsRichTextBox>
            rtb<FieldU>.Text != "" 
	            <ExitLoop>
	            <IsNotIdentityCount>
	            <And>
	            <IsNotPKeyCount>
	            <And>
	            <IsComboBox (Db)>
            cb<FieldU>.SelectedIndex != -1 
        	    <ExitLoop>
	            </If Loop>
            <If Loop>
	            <IsNotIdentityCount>
            )  {
            <OwnerU>_<TableU> cls<OwnerU>_<TableU> = new <OwnerU>_<TableU>();
	            <ExitLoop>
            </If Loop>
            <If Loop>
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsNumericUpDown>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(nud<FieldU>.Value);
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(tb<FieldU>.Text);
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsMaskedTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(mtb<FieldU>.Text);
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsMultilineTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(mtb<FieldU>.Text);
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
	            <IsRichTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(rtb<FieldU>.Text);
	            <IsNotIdentity>
	            <And>
	            <IsPKey>
	            <And>
        	    <IsComboBox (Db)>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(cb<FieldU>.SelectedValue);
            </If Loop>
            <If Loop>
	            <IsNotIdentityCount>
	            <And>
	            <IsNotPKeyCount>
	            <And>
	            <IsNumericUpDown>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(nud<FieldU>.Value);
	            <ExitLoop>
	            <IsNotIdentityCount>
	            <And>
	            <IsNotPKeyCount>
	            <And>
	            <IsTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(tb<FieldU>.Text);
	            <ExitLoop>
	            <IsNotIdentityCount>
	            <And>
	            <IsNotPKeyCount>
	            <And>
	            <IsMaskedTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(mtb<FieldU>.Text);
	            <ExitLoop>
	            <IsNotIdentityCount>
	            <And>
	            <IsNotPKeyCount>
	            <And>
	            <IsMultilineTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(mtb<FieldU>.Text);
	            <ExitLoop>
	            <IsNotIdentityCount>
	            <And>
	            <IsNotPKeyCount>
	            <And>
	            <IsRichTextBox>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(rtb<FieldU>.Text);
	            <ExitLoop>
	            <IsNotIdentityCount>
	            <And>
	            <IsNotPKeyCount>
	            <And>
	            <IsComboBox (Db)>
            cls<OwnerU>_<TableU>.<FieldU> = <Convert>(cb<FieldU>.SelectedValue);
        	    <ExitLoop>
            </If Loop>
            <If Loop>
	            <IsNotIdentityCount>
            cls<OwnerU>_<TableU> = <OwnerU>_<TableU>DataClass.Select_Record(cls<OwnerU>_<TableU>);
            if (cls<OwnerU>_<TableU> != null && this.AddMode == true) {
                 MessageBox.Show("Record already exists", "Error", MessageBoxButtons.OK);
	            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsNumericUpDown>
                 nud<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsTextBox>
                 tb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMaskedTextBox>
                 mtb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsMultilineTextBox>
                   mtb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsRichTextBox>
                   rtb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentity>
            <And>
            <IsPKey>
            <And>
            <IsComboBox (Db)>
                   cb<FieldU>.Select();
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsNumericUpDown>
                   nud<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsTextBox>
                  tb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMaskedTextBox>
                   mtb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsMultilineTextBox>
                  mtb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsRichTextBox>
                  rtb<FieldU>.Select();
            <ExitLoop>
            <IsNotIdentityCount>
            <And>
            <IsNotPKeyCount>
            <And>
            <IsComboBox (Db)>
                   cb<FieldU>.Select();
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
                  return false; }
            <ExitLoop>
            </If Loop>
            <If Loop>
            <IsNotIdentityCount>
            }
            <ExitLoop>
            </If Loop>
---------------------------------------<Comment>
            return true;
        }

        private void ShowToolStripItems(string Item)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            bAdd.Enabled = false;
            bEdit.Enabled = false;
            bDelete.Enabled = false;
            bCancel.Enabled = false;
            bRefresh.Enabled = false;
            switch (Item)
            {
                case "Add":
                    bCancel.Enabled = true;
                    break;
                case "Edit":
                    bCancel.Enabled = true;
                    break;
                case "Delete":
                    bCancel.Enabled = true;
                    break;
                case "Cancel":
                    if (gridCode.Rows.Count == 0)
                    {
                        ShowToolStripItems("No Record");
                    }
                    else
                    {
                        bAdd.Enabled = true;
                        bEdit.Enabled = true;
                        bDelete.Enabled = true;
                        bRefresh.Enabled = true;
                        ShowHideTabPages(TPGrid, TPForm);
                    }
                    break;
                case "Refresh":
                    bAdd.Enabled = true;
                    bEdit.Enabled = true;
                    bDelete.Enabled = true;
                    bRefresh.Enabled = true;
                    LoadGridCode(true);
                    break;
                case "No Record":
                    bAdd.Enabled = true;
                    ShowHideTabPages(TPGrid, TPForm);
                    break;
            }
            TPForm.Text = Item.Trim();
            TPGrid.Text = "<Owner>.<Table>";
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void ShowHideTabPages(TabPage Show, TabPage Hide)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            //if (this.TC.TabPages.Contains(Hide)) {
            //    this.TC.TabPages.Remove(Hide);}
            //if (this.TC.TabPages.Contains(Show)) {
            //    this.TC.TabPages.Remove(Show);}
            //if (!this.TC.TabPages.Contains(Show)) {
            //    this.TC.TabPages.Add(Show);}

            TC.ItemSize = new Size(0, 1);
            TC.Appearance = TabAppearance.FlatButtons;
            TC.SelectedTab = Show;
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void TS_ItemClicked(object sender, System.Windows.Forms.ToolStripItemClickedEventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            if (e.ClickedItem.Text != "Export") {
                ShowToolStripItems(e.ClickedItem.Text);
                TPForm.Text = e.ClickedItem.Text.Trim(); }
            switch (e.ClickedItem.Text)
            {
                case "Add":
                    ShowHideTabPages(TPForm, TPGrid);
                    Add();
                    break;
                case "Edit":
                    ShowHideTabPages(TPForm, TPGrid);
                    Edit();
                    break;
                case "Delete":
                    ShowHideTabPages(TPForm, TPGrid);
                    Delete();
                    break;
                case "Cancel":
                    ShowToolStripItems("Cancel");
                    break;
                case "Refresh":
                    GoBack_To_Grid();
                    break;
            }
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

	private void bWord_Click(object sender, System.EventArgs e)
	{
		this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
		if (TC.SelectedTab == TPForm) {
			<Database>DataClass.ExportToWord("One", this.Text, gridCode);
		} else if (TC.SelectedTab == TPGrid) {
			<Database>DataClass.ExportToWord("Many", this.Text, gridCode);
		}
		this.Cursor = System.Windows.Forms.Cursors.Default;
	}

	private void bExcel_Click(object sender, System.EventArgs e)
	{
		this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
		if (TC.SelectedTab == TPForm) {
			<Database>DataClass.ExportToExcel("One", this.Text, gridCode);
		} else if (TC.SelectedTab == TPGrid) {
			<Database>DataClass.ExportToExcel("Many", this.Text, gridCode);
		}
		this.Cursor = System.Windows.Forms.Cursors.Default;
	}

	private void bPDF_Click(object sender, System.EventArgs e)
	{
		this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
		if (TC.SelectedTab == TPForm) {
			<Database>DataClass.ExportToPDF("One", this.Text, gridCode, gridCode.CurrentRow);
		} else if (TC.SelectedTab == TPGrid) {
			<Database>DataClass.ExportToPDF("Many", this.Text, gridCode, gridCode.CurrentRow);
		}
		this.Cursor = System.Windows.Forms.Cursors.Default;
	}

        <If Loop>
        <IsNotIdentity>
        <And>
        <IsFieldD>
        <And>
        <IsCheckBox>
        private void cb<FieldU>_GotFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = "<FieldD>";
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void cb<FieldU>_LostFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = null;
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
        <IsNotIdentity>
        <And>
        <IsFieldD>
        <And>
        <IsNumericUpDown>
        private void nud<FieldU>_GotFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = "<FieldD>";
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void nud<FieldU>_LostFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = null;
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
        <IsNotIdentity>
        <And>
        <IsFieldD>
        <And>
        <IsDateTimePicker>
        private void dtp<FieldU>_GotFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = "<FieldD>";
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void dtp<FieldU>_LostFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = null;
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
        <IsNotIdentity>
        <And>
        <IsFieldD>
        <And>
        <IsTextBox>
        private void tb<FieldU>_GotFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = "<FieldD>";
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void tb<FieldU>_LostFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = null;
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
        <IsNotIdentity>
        <And>
        <IsFieldD>
        <And>
        <IsMaskedTextBox>
        private void mtb<FieldU>_GotFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = "<FieldD>";
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void mtb<FieldU>_LostFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = null;
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
        <IsNotIdentity>
        <And>
        <IsFieldD>
        <And>
        <IsMultilineTextBox>
        private void mtb<FieldU>_GotFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = "<FieldD>";
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void mtb<FieldU>_LostFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = null;
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
        <IsNotIdentity>
        <And>
        <IsFieldD>
        <And>
        <IsRichTextBox>
        private void rtb<FieldU>_GotFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = "<FieldD>";
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void rtb<FieldU>_LostFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = null;
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
        <IsNotIdentity>
        <And>
        <IsFieldD>
        <And>
        <IsPictureBox>
        private void pb<FieldU>_GotFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = "<FieldD>";
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void pb<FieldU>_LostFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = null;
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
        <IsNotIdentity>
        <And>
        <IsFieldD>
        <And>
        <IsComboBox>
        private void cb<FieldU>_GotFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = "<FieldD>";
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void cb<FieldU>_LostFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = null;
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
        <IsNotIdentity>
        <And>
        <IsFieldD>
        <And>
        <IsComboBox (Db)>
        private void cb<FieldU>_GotFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = "<FieldD>";
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }

        private void cb<FieldU>_LostFocus(object sender, System.EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            SSLabel.Text = null;
            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
        </If Loop>
    }
}





